<?php

namespace app\api\controller\supplier;

use addons\wechat\library\Config as ConfigService;
use AlibabaCloud\SDK\Iot\V20180120\Iot;
use AlibabaCloud\SDK\Iot\V20180120\Models\PubRequest;
use app\admin\model\AssistantOrder;
use app\admin\model\Chargecode;
use app\admin\model\Cmdlog;
use app\admin\model\Devicelock;
use app\admin\model\Linedevice;
use app\admin\model\litestore\Litestoreorder;
use app\admin\model\litestore\Litestoreorderaddress;
use app\admin\model\litestore\Litestoreordergoods;
use app\admin\model\Mallsupplier;
use app\admin\model\Org;
use app\admin\model\Roomclean;
use app\admin\model\Shop;
use app\admin\model\Shopcharge;
use app\admin\model\Shopchargeconfig;
use app\admin\model\Shopdaytrade;
use app\admin\model\Shopdevice;
use app\admin\model\Shopmno;
use app\admin\model\Shoporder;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproom;
use app\admin\model\Shoproombook;
use app\admin\model\Shoproomset;
use app\admin\model\Shoptableorder;
use app\admin\model\Supplierorderservice;
use app\admin\model\Tuanorder;
use app\admin\model\Userbalance;
use app\admin\model\Userorderprofit;
use app\admin\model\Usertuan;
use app\admin\model\Userwithdraw;
use app\api\controller\Exception;
use App\Api\PrinterService;
use App\Api\PrintService;
use app\api\service\AirService;
use app\api\service\BalanceService;
use app\api\service\DeviceService;
use app\api\service\LockService;
use app\api\service\MpService;
use app\api\service\MtService;
use app\api\service\MtUtil;
use app\api\service\RoomService;
use app\api\service\VbillService;
use app\api\service\XhtMtService;
use app\common\controller\Api;
use App\Config\YlyConfig;
use App\Oauth\YlyOauthClient;
use Darabonba\GatewaySpi\Models\InterceptorContext\request;
use Darabonba\OpenApi\Models\Config;
use EasyWeChat\Factory;
use fast\Http;
use PhpMqtt\Client\ConnectionSettings;
use PhpMqtt\Client\MQTTClient;
use think\Console;
use think\exception\HttpResponseException;
use think\Response;
use Workerman\Mqtt\Client;
use Workerman\Worker;

/**
 * 首页接口
 */
class Service extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];




    public function getList()
    {
        $status = $this->request->param('status');
        $page = $this->request->param('page');
        $user = $this->auth->getUser();
        $mallSupplierModel = new Mallsupplier();
        $supplier = $mallSupplierModel->where('mobile',$user['mobile'])->find();

        $limit = 10;
        $offset = ($page - 1) * $limit;

        $where = array();
        $where['supplier_id'] = $supplier['id'];
        if($status == ''){
            $where['status'] = ['<>','done'];

        }else{
            $where['status'] = $status;

        }

        $supplierOrderService = new Supplierorderservice();
        $list = $supplierOrderService->where($where)->limit($offset,$limit)->order('create_time','desc')->select();


        $orderDetailModel = new Litestoreordergoods();
        foreach ($list as $key=>$val){

            $list[$key]['images'] = cdnurl($val['images'],true);
            $detail = $orderDetailModel->where('id',$val['order_good_id'])->find();
            $detail['images'] = cdnurl($detail['images'],true);
            $list[$key]['detail'] = $detail;
        }

        $total = $supplierOrderService->where($where)->count('id');

        $ret = array();
        $ret['list'] = $list;
        $ret['total'] = $total;
        $this->success('',$ret);
    }


     public function updateStatus()
     {

         $id = $this->request->param('id');
         $status = $this->request->param('status');
         $user = $this->auth->getUser();
         $mallSupplierModel = new Mallsupplier();
         $supplier = $mallSupplierModel->where('mobile',$user['mobile'])->find();


         $serviceModel = new Supplierorderservice();
         $service = $serviceModel->where('id',$id)->find();
         if($service['supplier_id']  != $supplier['id']) $this->error("无权限操作");
         $serviceModel->where('id',$id)->update(['status'=>$status]);

         $this->success('成功');
     }

}

